package com.zj.study.file;

import com.alibaba.fastjson.JSONObject;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

/**
 * <p>Title: FileTxtTest1</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2024 版权</p>
 * <p>Company: Oceanpayment</p>
 *
 * @author Jerry Zhao
 * @version V1.0
 * @date 2024年07月24号 19点39分38秒
 */
public class FileTxtTest1 {

    public static void main(String[] args) {
        try {
            //txt 文件是一行一行读 所以要用个东西给他存起来
            StringBuilder lingStrbuf = new StringBuilder();
            // TODO Auto-generated method stub
            String path="C:\\Users\\jerryzhao\\Desktop\\20240713000000-customerNegativeBalanceReport-XYZ_program_mgmt-Goldcard.txt";//定义文件路径名称
            //文件输入流
            FileInputStream fs= new FileInputStream(path);
            //内存输入流
            InputStreamReader is=new InputStreamReader(fs, StandardCharsets.UTF_8);
            BufferedReader br=new BufferedReader(is);
            String line=br.readLine();


            while(line!=null){
//                System.out.println(line);
                lingStrbuf.append(line);
                line=br.readLine();
            }
            //释放资源
            br.close();
            is.close();
            fs.close();
            System.out.println(lingStrbuf);
            String Str = lingStrbuf.toString();
            //  这里就是将StringBuilder 转成String 类型后用下面的方式转成对象
            JSONObject jso = JSONObject.parseObject(Str);
            System.out.println("jso = " + jso);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}